fix: prevent numerical metadata values from being incorrectly formatted as dates#2213
fix: prevent numerical metadata values from being incorrectly formatted as dates#2213
Conversation
| if (scientificMetadata.type) { | ||
| return scientificMetadata.type === "date"; |
There was a problem hiding this comment.
I'm not sure about this change, previous code returns only when type is date but with this change it returns when type exist. Is it really the fix? Are you sure that the codes below should not executed when there is type?
There was a problem hiding this comment.
To my understanding the purpose is to check if the value is a date. So if it has a type, which is not Date, it is not necessary to run the code below because it shouldn't be a date. But if the type is undefined, the code below has to check if it is a date. Of course this assumes that the type is set correctly.
And the old code would turn "2010" into a Date because new Date("2010").toString() is a valid date. However, I just noticed, that if the type is not defined, the 2010 would still be interpreted as a Date, which would still be wrong. So the heuristic below needs to be stricter?
Or am I missing something?
There was a problem hiding this comment.
Unfortunately, the type concept exists only on the frontend. On the backend we do not constraint users from creating any arbitary scientific metadata with any values regardless of the type.
It means that, User can create any type of date. It could be string date, numeric date(timestamp) , date date, but of course most cases user don't provide type at all, since its not required.
Hence I don't see this PR fixes the root. Stricter validation could be one way.
Description
This PR fixes a bug where numeric metadata values (like "10") were being incorrectly displayed as dates (like "1970-01-01 01:00") in the metadata view table. The fix ensures that when metadata has a type field set (such as "number" or "quantity"), that type is respected and the value is displayed correctly.
Motivation
Background on use case, changes needed
Fixes:
Please provide a list of the fixes implemented in this PR
Changes:
Please provide a list of the changes implemented by this PR
Tests included
Documentation
official documentation info
If you have updated the official documentation, please provide PR # and URL of the pages where the updates are included
Backend version
Summary by Sourcery
Bug Fixes: